package IC.SymbolTable;

import java.util.ArrayList;
import java.util.List;

import IC.AST.Formal;
import IC.AST.Method;
import IC.TypeTable.TypeTable;

public class MethodSymbol extends Symbol 
{
	private boolean isStaticMethod;

	public MethodSymbol(String symID, IC.TypeTable.Type returnType, List<IC.TypeTable.Type> formalparamTypes, boolean isStatic)
	{

		super(symID, TypeTable.addMethodType(returnType, formalparamTypes), null);

		isStaticMethod = isStatic;

		if (isStaticMethod)
		{
			
			this.kind = Kind.STATICMETHOD;
		}

		else
		{
		  
			this.kind = Kind.VIRTUALMETHOD;
		}



	}

	public MethodSymbol(Method m) throws SemanticError{

		super(m.getName(), null, null);
		
		isStaticMethod = m.isStatic();
		
		if (isStaticMethod)
		{
		  
			this.kind = Kind.STATICMETHOD;
		}

		else
		{
		  
			this.kind = Kind.VIRTUALMETHOD;
		}
		

		List<IC.TypeTable.Type> paramTypes = new ArrayList<IC.TypeTable.Type>();
		for (Formal f: m.getFormals()){
			paramTypes.add((TypeTable.getType(f.getType().getArrName()))); 
		}
		IC.TypeTable.Type retType = TypeTable.getType(m.getType().getArrName());

		this.type = TypeTable.addMethodType(retType, paramTypes);


	}

	public boolean isStaticMethod() {
		return isStaticMethod;
	}

	
	
	

}